if(window.plus) {
	plusReady();
} else {
	document.addEventListener('plusready', plusReady, false);
}

function plusReady() {

	var o_psg_sn = getData("o_psg_sn");
	var flightno = getData("flightno");

	//		alert(">>>>>>>>>>>>>>>>>>>>" + o_psg_sn);
	//		alert("####################" + flightno);

	$(document).ready(function() {

		UpdateState();
		load_seatInfo();
	});

	function load_seatInfo() {
		UpdateState();
		if(!isOnLine) {
			loadSeats();
		} else {
			var url = server_url+'/9airweb/getCardInfo.action?o_psg_sn='+o_psg_sn+'&flightno='+flightno;
//			var url = 'http://10.200.107.102:8080/9airweb/getCardInfo.action?o_psg_sn=' + o_psg_sn + '&flightno=' + flightno;
			//			url += url_tail;
			var myDate = new Date();
			console.log(url);

			$.ajax({
				dataType: "json",
				url: url,
				timeout: 30000
			}).done(function(backdata, status) {
				if(status == 'success') {
					if(setData('PsgInfo' + o_psg_sn + flightno, backdata)) {
						var myDate = new Date();
						console.log("数据更新成功！");
						loadSeats();
					}
				}
			}).fail(function(jqXHR, textStatus) {
				if(textStatus == 'timeout') {
					plus.nativeUI.alert("数据更新失败，即将加载本地数据！", "OK");
					loadSeats();
				}
			});
		}
	}

	function loadSeats() {
		$("#caseVerteClaire").hide();
		var seatsInfo = getData('PsgInfo' + o_psg_sn + flightno);
		if(!seatsInfo) {
			plus.nativeUI.alert("本地无数据，请连接网络刷新数据！")
			window.location.href = "index.html";
			return;
		}
		var flight_data = seatsInfo.msg;

		if(seatsInfo.type != "data") {
			plus.nativeUI.alert(seatsInfo.msg);
		} else {
			setSeats();
		}

		//seats
		function setSeats() {
			$("#healths").empty();
			var div_col = getPsgInfoByXY();
			$($.parseHTML(div_col)).appendTo($("#healths"));
		}

		function getPsgInfoByXY() {
			var seatsInfo = getData('PsgInfo' + o_psg_sn + flightno);
			var flight_data = seatsInfo.msg;

			var idType_string = "";
			switch(flight_data.idType) {
				case "NI":
					idType_string = "身份证";
					break;
				case "PP":
					idType_string = "护照";
					break;
				case "HK":
					idType_string = "港澳通行证";
					break;
				case "RP":
					idType_string = "外国人永久居住证";
					break;
				case "TT":
					idType_string = "往来台湾通行证";
					break;
				case "WC":
					idType_string = "外国人出入证";
					break;
				case "PI":
					idType_string = "外国人永久居留身份证";
					break;
				default:
					idType_string = "其他";
					break;
			}
			
			var gender_string = "";
			switch(flight_data.gender) {
				case "F":
					gender_string = "女";
					break;
				case "M":
					gender_string = "男";
					break;
				case "CHD":
					gender_string = "儿童";
					break;
				case "INF":
					gender_string = "婴儿";
					break;
				default:
					gender_string = "其他";
					break;
			}

			var div_seat =
				'<div class="modal-body" style="padding-bottom: 0px;width:100%;text-align: center;">' +
				'<table class="table" style="text-align: center;">' +
				'<thead>' +
				'<tr>' +
				'<th>#</th>' +
				'<th>名称</th>' +
				'<th>内容</th>' +
				'</tr>' +
				'</thead>' +
				'<tbody>' +
				'<tr>' +
				'<td>1</td>' +
				'<td>航班号</td>' +
				'<td>' + flightno + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>2</td>' +
				'<td>航班日期</td>' +
				'<td>' + flight_data.deptDate + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>3</td>' +
				'<td>旅客姓名</td>' +
				'<td>' + flight_data.name + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>4</td>' +
				'<td>性别</td>' +
				'<td>' + gender_string + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>5</td>' +
				'<td>证件类型</td>' +
				'<td>' + idType_string + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>6</td>' +
				'<td>有效证件号</td>' +
				'<td>' + flight_data.idNo + '</td>' +
				'</tr>' +
			'<tr>' +
			'<td>7</td>' +
			'<td>手机号码</td>' +
			'<td>' + flight_data.phone + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>8</td>' +
				'<td>出生日期</td>' +
				'<td>' + flight_data.birthDate + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>9</td>' +
				'<td>卡片收集机场</td>' +
				'<td>' + flight_data.collectApt + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>10</td>' +
				'<td>起飞机场</td>' +
				'<td>' + flight_data.deptApt + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>11</td>' +
				'<td>14天内居住或到达路过湖北</td>' +
				'<td>' + (flight_data.passingHubei == true ? "是" : "否") + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>12</td>' +
				'<td>14天内接触过湖北疑似感染患者</td>' +
				'<td>' + (flight_data.contactHubei == true ? "是" : "否") + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>13</td>' +
				'<td>是否发热</td>' +
				'<td>' + (flight_data.symptomFever == true ? "是" : "否") + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>14</td>' +
				'<td>是否咳嗽</td>' +
				'<td>' + (flight_data.symptomCough == true ? "是" : "否") + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>15</td>' +
				'<td>是否乏力</td>' +
				'<td>' + (flight_data.symptomWeak == true ? "是" : "否") + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>16</td>' +
				'<td>其他症状</td>' +
				'<td>' + flight_data.symptomOther + '</td>' +
				'</tr>' +
				'<tr>' +
				'<td>17</td>' +
				'<td>家庭住址</td>' +
				'<td>' + flight_data.destAddress + '</td>' +
				'</tr>' +
				'</tbody>' +
				'</table>' +
				'</div>';

			return div_seat;
		}
	}
}